package sync.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.druid.pool.DruidDataSource;

import sync.bean.SSCBean;

public class ConnectionPool {

	// 服务器
	private static final String USERNAME = "root";
	private static final String PASSWORD = "12345";
	private static final String LOCALJDBC = "jdbc:mysql://127.0.0.1:3306/qwert";
//	
//	private static final String USERNAME = "root";
//	private static final String PASSWORD = "";
//	private static final String LOCALJDBC = "jdbc:mysql://127.0.0.1:3306/qwert";
	
	private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
	
	public static DruidDataSource dataSource;
	
	private ConnectionPool(){
	}
	
	public static DruidDataSource getInstance(){
		if(dataSource == null){
			return initDataSource();
		}
		return dataSource;
	}
	
	private static DruidDataSource initDataSource(){
		dataSource = new DruidDataSource();
		dataSource.setDriverClassName("com.mysql.jdbc.Driver"); 
		dataSource.setUsername(USERNAME); 
		dataSource.setPassword(PASSWORD); 
		dataSource.setUrl(LOCALJDBC); 
		dataSource.setInitialSize(5);
		dataSource.setMinIdle(1);
		dataSource.setMaxActive(10);
		// 启用监控统计功能  dataSource.setFilters("stat");
		// for mysql  
		dataSource.setPoolPreparedStatements(false);
		return dataSource;
	}
	
}
